package com.example.statistics.ui.sales

import com.example.statistics.R
import com.example.statistics.bean.Customer
import com.example.statistics.common.BaseLoadingListActivity
import com.example.statistics.ex.goTimeFormat
import com.example.statistics.net.UrlConfig
import com.example.statistics.utils.Constants
import com.jhj.slimadapter.SlimAdapter
import com.jhj.slimadapter.holder.ViewInjector
import org.jetbrains.anko.startActivity

class SalesCustomerListActivity : BaseLoadingListActivity<Customer>() {

    override val title: String
        get() = intent.getStringExtra(Constants.TITLE).orEmpty()

    override val url: String
        get() = UrlConfig.SALES_CUSTOMER_LIST

    override val itemLayoutRes: Int
        get() = R.layout.llist_item_sales_customer

    override val httpParams: MutableList<Pair<String, String>>
        get() = mutableListOf("productName" to title)


    override fun itemViewConvert(adapter: SlimAdapter, injector: ViewInjector, bean: Customer, position: Int) {
        if (!bean.salesProductList.isNullOrEmpty()) {
            val product = bean.salesProductList?.get(0)
            injector.text(R.id.tv_name, bean.name?.replace("?", "")?.replace("？", ""))
                    .text(R.id.tv_number, "${product?.factoryNo}${product?.productName}：${product?.salesNumber}件 * ￥${product?.salesPrice}")
                    .text(R.id.tv_date, product?.date.goTimeFormat())
                    .clicked {
                        startActivity<SalesCustomerInfoActivity>(Constants.ID to bean.ID)
                    }
        }
    }


}